package com.seguriapp.entities;

import java.util.Date;
import java.util.LinkedHashMap;
import java.util.Map;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.hibernate.annotations.Proxy;

import com.seguriapp.base.BaseEntity;
import com.seguriapp.util.Util;

/**
 * Represents an Alert entity.
 * 
 * @author Tania Gonzales(taniadgv@gmail.com)
 */
@Entity
@Table(name = "Alert")
@Proxy(lazy = false)
public class Alert extends BaseEntity {

  private static final long serialVersionUID = 1949483443995047105L;

  @Id
  @GeneratedValue
  private Long id;

  private double latitude;
  private double longitude;
  private String names;
  private String lastNames;
  private String dni;
  private Date date;
  private String phone;
  private String postalCode;
  private String address;

  @ManyToOne(cascade = { CascadeType.PERSIST, CascadeType.MERGE })
  @JoinColumn(nullable = false, name = "entityId")
  private SeguriAppEntity entity;

  public Long getId() {
    return id;
  }

  public double getLatitude() {
    return latitude;
  }

  public double getLongitude() {
    return longitude;
  }

  public String getNames() {
    return names;
  }

  public String getLastNames() {
    return lastNames;
  }

  public String getDni() {
    return dni;
  }

  public Date getDate() {
    return date;
  }

  public String getPhone() {
    return phone;
  }

  public SeguriAppEntity getEntity() {
    return entity;
  }

  public final String getPostalCode() {
    return postalCode;
  }

  public void setId(final Long id) {
    this.id = id;
  }

  public void setLatitude(final double latitude) {
    this.latitude = latitude;
  }

  public void setLongitude(final double longitude) {
    this.longitude = longitude;
  }

  public void setNames(final String names) {
    this.names = names;
  }

  public void setLastNames(final String lastNames) {
    this.lastNames = lastNames;
  }

  public void setDni(final String dni) {
    this.dni = dni;
  }

  public void setDate(final Date date) {
    this.date = date;
  }

  public void setPhone(final String phone) {
    this.phone = phone;
  }

  public void setEntity(final SeguriAppEntity entity) {
    this.entity = entity;
  }

  public final void setPostalCode(final String postalCode) {
    this.postalCode = postalCode;
  }

  public String getAddress() {
	return address;
  }

  public void setAddress(final String address) {
	this.address = address;
  }

  public Map<String, Object> toJsonString() {
    final Map<String, Object> map = new LinkedHashMap<String, Object>();
    map.put("id", id);
    map.put("latitude", latitude);
    map.put("longitude", longitude);
    map.put("names", names);
    map.put("lastNames", lastNames);
    map.put("dni", dni);
    map.put("date", Util.parseDateToString(date));
    map.put("phone", phone);
    map.put("address", address);
    map.put("entity", entity.toJsonString());
    return map;
  }

}
